package main

import (
	"fmt"
	"go_web_bubble/dao"
	"go_web_bubble/routers"
	"go_web_bubble/setting"
	"os"
)

func main() {
	if len(os.Args) < 2 {
		fmt.Println("Usage：./bubble conf/config.ini")
		return
	}
	// 加载配置文件(需要在命令行传递参数告知配置文件的位置，比如 go run main.go conf/config.ini)
	if err := setting.Init(os.Args[1]); err != nil {
		fmt.Printf("load config from file failed, err:%v\n", err)
		return
	}
	err := dao.InitMysql(setting.Conf.MySQLConfig)
	if err != nil {
		fmt.Printf("init mysql connect failed,err:%v\n", err)
		return
	}
	defer dao.Close() //程序退出关闭数据库连接
	//dao.DB.AutoMigrate(&models.Bubble{}) //数据迁移，模型绑定
	r := routers.SetupRouter()

	if err := r.Run(":8888"); err != nil {
		fmt.Printf("server startup failed, err:%v\n", err)
	}
}
